<template>
  <div>
    <h1>我的课表</h1>
    <!-- <el-input size="medium" v-model="search_cno" placeholder="请输入课程编号"></el-input>
    <el-button @click="search()" icon="el-icon-search" circle></el-button> -->
    <el-table
      :data="tableData"
      border
      style="width:100%">
      <el-table-column
        fixed
        prop="cno"
        label="课程编号"
        width="150">
      </el-table-column>
      <el-table-column
        label="操作"
        width="50">
        <template slot-scope="scope">
          <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "MyCourse",
  data() {
    return {
      stuNo:'',
      tableData:null
    }
  },
  created(){
    //this.stuNo = localStorage.getItem("stuno");
    // console.log(this.cno);
    // console.log(this.stuNo);
    const  _this = this;
    console.log("准备接受数据：");
    this.$axios.post(`http://localhost:8081/MyCourse`).then((res) => {
      console.log("接受的数据为：", res.data);
      this.tableData = res.data;

    })
  },
  methods:{
    del(row){
      this.$axios.post(`http://localhost:8081/DeleteMyCourse`, {cno:row.cno}).then((res) => {
        // console.log("接受的数据为：", res.data);
        // this.tableData = res.data;
        // if (res.data.msg=="删除成功") {
        //   alert("删除成功")
        // } else {
        //   alert(res.data.msg)
        // }
        this.$alert("课号："+ row.cno + "删除成功", "提示", {
          confirmButtonText:'确定',

        })
        this.$router.push({path:'/MyCourse', query:{}})
      })
    }
  },
}
</script>

<style scoped>

</style>
